home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / MiniGames / PTB / PushTheBusMG.as
Text File  |  2013-04-24  |  6KB  |  176 lines

  1. class MiniGames.PTB.PushTheBusMG extends MiniGames.BaseMiniGame
  2. {
  3.    static var sSTATE_SANDY = "Sandy";
  4.    static var sSTATE_BOB = "SpongeBob";
  5.    static var sSTATE_SANDY_WHACKY = "SandyWhacky";
  6.    static var sSTATE_BOB_WHACKY = "BobWhacky";
  7.    static var nDIR_LEFT = 1;
  8.    static var nDIR_RIGHT = 2;
  9.    static var nTIME_TO_PUSH_SANDY = 40;
  10.    static var nTIME_TO_PUSH_BOB = 70;
  11.    static var nMAX_TIME = 16;
  12.    static var nSECOND_VALUE = 100;
  13.    static var nRANGE_SANDY = 40;
  14.    static var nRANGE_BOB = 40;
  15.    function PushTheBusMG(_mcRef)
  16.    {
  17.       super(_mcRef);
  18.       this.nDone = 0;
  19.       if(CTRLGame.getRef().Level == CTRLGame.nLEVEL1)
  20.       {
  21.          this.bModeSandy = true;
  22.          this.nRange = MiniGames.PTB.PushTheBusMG.nRANGE_SANDY;
  23.          this.nNumberTimes = MiniGames.PTB.PushTheBusMG.nTIME_TO_PUSH_SANDY;
  24.       }
  25.       else
  26.       {
  27.          this.bModeSandy = false;
  28.          this.nRange = MiniGames.PTB.PushTheBusMG.nRANGE_BOB;
  29.          this.nNumberTimes = MiniGames.PTB.PushTheBusMG.nTIME_TO_PUSH_BOB;
  30.       }
  31.       this.nNextDir = MiniGames.PTB.PushTheBusMG.nDIR_LEFT;
  32.       this.showInstructions();
  33.    }
  34.    function initMiniGame()
  35.    {
  36.       this.mcRef.mcState.mcMode.mcBus.mcStrenght.gotoAndStop(this.mcRef.mcState.mcStrenght._totalframes);
  37.       this.nPosX = 300;
  38.    }
  39.    function calculateScore()
  40.    {
  41.       this.addScoreFromTimeLeft(MiniGames.PTB.PushTheBusMG.nMAX_TIME,MiniGames.PTB.PushTheBusMG.nSECOND_VALUE);
  42.    }
  43.    function validateEndMiniGame()
  44.    {
  45.       if(this.nDone >= this.nNumberTimes)
  46.       {
  47.          this.setVictory();
  48.       }
  49.    }
  50.    function setState(_sState)
  51.    {
  52.       super.setState(_sState);
  53.       this.setPlayCharacter();
  54.    }
  55.    function doPause()
  56.    {
  57.       super.doPause();
  58.       if(this.sState == MiniGames.BaseMiniGame.sSTATE_MINIGAME)
  59.       {
  60.          this.mcRef.mcState.mcBus.stop();
  61.       }
  62.       else if(this.sState == MiniGames.BaseMiniGame.sSTATE_VICTORY)
  63.       {
  64.          this.mcRef.mcState.mcMode.stop();
  65.          this.mcRef.mcState.mcMode.mcBus.stop();
  66.       }
  67.    }
  68.    function doUnPause()
  69.    {
  70.       super.doUnPause();
  71.       this.mcRef.mcState.stop();
  72.       if(this.sState == MiniGames.BaseMiniGame.sSTATE_MINIGAME)
  73.       {
  74.          this.mcRef.mcState.mcBus.play();
  75.       }
  76.       else if(this.sState == MiniGames.BaseMiniGame.sSTATE_VICTORY)
  77.       {
  78.          this.mcRef.mcState.mcMode.play();
  79.          this.mcRef.mcState.mcMode.mcBus.play();
  80.       }
  81.    }
  82.    function setPlayCharacter()
  83.    {
  84.       if(this.bModeSandy)
  85.       {
  86.          if(Main.getRef().isCheatClothesActivated())
  87.          {
  88.             this.mcRef.mcState.gotoAndStop(MiniGames.PTB.PushTheBusMG.sSTATE_SANDY_WHACKY);
  89.          }
  90.          else
  91.          {
  92.             this.mcRef.mcState.gotoAndStop(MiniGames.PTB.PushTheBusMG.sSTATE_SANDY);
  93.          }
  94.       }
  95.       else if(Main.getRef().isCheatClothesActivated())
  96.       {
  97.          this.mcRef.mcState.gotoAndStop(MiniGames.PTB.PushTheBusMG.sSTATE_BOB_WHACKY);
  98.       }
  99.       else
  100.       {
  101.          this.mcRef.mcState.gotoAndStop(MiniGames.PTB.PushTheBusMG.sSTATE_BOB);
  102.       }
  103.       var _loc2_ = this.mcRef.mcState.mcMode.mcBus.mcStrenght._totalframes / this.nNumberTimes * this.nDone;
  104.       this.mcRef.mcState.mcMode.mcBus.mcStrenght.gotoAndStop(100 - Math.round(_loc2_));
  105.    }
  106.    function onKeyPressed()
  107.    {
  108.       this.nDone = this.nDone + 1;
  109.       var _loc2_ = this.mcRef.mcState.mcMode.mcBus.mcStrenght._totalframes / this.nNumberTimes * this.nDone;
  110.       this.mcRef.mcState.mcMode.mcBus.mcStrenght.gotoAndStop(100 - Math.round(_loc2_));
  111.    }
  112.    function validateActions()
  113.    {
  114.       if(!Controller.getRef().isPaused())
  115.       {
  116.          if(this.nNextDir == MiniGames.PTB.PushTheBusMG.nDIR_LEFT)
  117.          {
  118.             if(CTRLGame.getRef().mcRef._xmouse <= this.nPosX - this.nRange)
  119.             {
  120.                this.onKeyPressed();
  121.                this.nNextDir = MiniGames.PTB.PushTheBusMG.nDIR_RIGHT;
  122.             }
  123.          }
  124.          else if(this.nNextDir == MiniGames.PTB.PushTheBusMG.nDIR_RIGHT)
  125.          {
  126.             if(CTRLGame.getRef().mcRef._xmouse >= this.nPosX + this.nRange)
  127.             {
  128.                this.nNextDir = MiniGames.PTB.PushTheBusMG.nDIR_LEFT;
  129.                this.onKeyPressed();
  130.             }
  131.          }
  132.       }
  133.    }
  134.    function setVictory()
  135.    {
  136.       this.setState(MiniGames.BaseMiniGame.sSTATE_VICTORY);
  137.       CTRLGame.getRef().Screen.getInterface().pauseTime();
  138.       this.mcRef.mcState.mcMode.mcBus.mcStrenght.stop();
  139.       Controller.getRef().getSounds().playSound("alguaetore",Controller.nSFX_VOLUME,1);
  140.    }
  141.    function HowToPlayIn()
  142.    {
  143.       if(this.mcRef.mcState.mcMode._currentframe == this.mcRef.mcState.mcMode._totalframes)
  144.       {
  145.          this.setState(MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_IDLE);
  146.          this.initSkipKeys();
  147.       }
  148.    }
  149.    function HowToPlayIdle()
  150.    {
  151.       if(this.mcRef.mcState.mcMode._currentframe == this.mcRef.mcState.mcMode._totalframes)
  152.       {
  153.          this.setState(MiniGames.BaseMiniGame.sSTATE_HOWTOPLAY_OUT);
  154.       }
  155.    }
  156.    function HowToPlayOut()
  157.    {
  158.       if(this.mcRef.mcState.mcMode._currentframe == this.mcRef.mcState.mcMode._totalframes)
  159.       {
  160.          this.startGame();
  161.       }
  162.    }
  163.    function MiniGame()
  164.    {
  165.       super.MiniGame();
  166.       this.validateActions();
  167.    }
  168.    function Victory()
  169.    {
  170.       if(this.mcRef.mcState.mcMode._currentframe == this.mcRef.mcState.mcMode._totalframes - 15)
  171.       {
  172.          this.bOver = true;
  173.       }
  174.    }
  175. }
  176.